<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class m_statistik_kunjungan extends CI_Model {

	public function __construct() {
		parent::__construct();
	}

	function get() {
		$sql = 'SELECT Tanggal, 
					(SELECT count(KdKunjungan) FROM kunjungan WHERE tanggal = k.tanggal) as pengunjung 
				FROM kunjungan k
				GROUP BY Tanggal ORDER BY Tanggal ASC';
		return $sql;
	}

	function get_cari($tgl_awal,$tgl_akhir) {
		$sql = 'SELECT Tanggal, 
					(SELECT count(KdKunjungan) FROM kunjungan WHERE tanggal = k.tanggal) as pengunjung 
				FROM kunjungan k
				WHERE tanggal BETWEEN "'.$tgl_awal.'" AND "'.$tgl_akhir.'"
				GROUP BY Tanggal ORDER BY Tanggal ASC';
		return $sql;
	}

	function get_export_all() {
		$sql = 'SELECT Tanggal, 
					(SELECT count(KdKunjungan) FROM kunjungan WHERE tanggal = k.tanggal) as pengunjung 
				FROM kunjungan k
				GROUP BY Tanggal ORDER BY Tanggal ASC';
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			$result = $query->result_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}

	function get_export_by($tgl_awal,$tgl_akhir) {
		$sql = 'SELECT Tanggal, 
					(SELECT count(KdKunjungan) FROM kunjungan WHERE tanggal = k.tanggal) as pengunjung 
				FROM kunjungan k
				WHERE tanggal BETWEEN "'.$tgl_awal.'" AND "'.$tgl_akhir.'"
				GROUP BY Tanggal ORDER BY Tanggal ASC';
		$query = $this->db->query($sql);
		if ($query->num_rows() > 0) {
			$result = $query->result_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}
}
